package com.qing.springcloud.utils;

import com.qing.springcloud.dto.user.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author caozhipeng
 * @date 2025/7/21
 */
@Component
public class UserInfoUtils {

    @Autowired
    private RedisUtils redisUtils;

    public void setUserInfo(Long userId, UserDTO userDTO){
        redisUtils.set("userInfo:"+userId, userDTO,60*60*24);
    }

    public UserDTO getUserInfo(Long userId)  {
        return redisUtils.get("userInfo:"+userId, UserDTO.class);
    }

    public String getUserName(Long userId)  {
        return redisUtils.get("userInfo:"+userId, UserDTO.class).getUsername();
    }

    public String getNickName(Long userId)  {
        return redisUtils.get("userInfo:"+userId, UserDTO.class).getNickname();
    }
}
